package cn.itcast.javaobject;

/**
 * @title: VariableParameter01
 * @Author Zhou
 * @Date: 2022/1/4 15:16
 * @Version 1.0
 */
public class VariableParameter01 {
    public static void main(String[] args) {
        HspMethod hspMethod = new HspMethod();
        System.out.println(hspMethod.sum(1, 2, 4));
        System.out.println(hspMethod.sum(2, 4));
    }
}

class HspMethod {
    //可变参数,形参可当作数组来使用，即使用nums可以当作数组
    public int sum(int... nums) {
        System.out.println("参数个数" + nums.length);
        int res = 0;
        for (int num : nums) {
            res += num;
        }
        return res;
    }
}
